'''
Created on 21/02/2011

@author: Vinicius
'''
from funcoes import define_input
import mlp
from scipy.cluster.vq import whiten
entrada = define_input('../iris.data')

input = whiten(entrada[0])
desired = [None]*len(input)
for i in range(len(entrada[1])):
    if entrada[1][i] == 'Iris-setosa':
        desired[i] = 1.0
    else: 
        desired[i] = 0.0
        
print '\n===== Multi-layer perceptrons: backpropagation algorithm =====\n'
print '\nComputing perceptrons (wait) ...'
output = mlp.execute(input,hiddenNeurons=2,outputNeurons=1,desiredOutput=desired,alfa=1.0,rate=0.1,errorThreshold=0.005,maxEpochs=500)
print '...done\n'

saida = output[2]
epocas = output[3]

erro = 0
for i in range(len(input)):
    print '#'+str(i)+': '+'d[i]: '+str(desired[i])+' y[0][i]: '+str(saida[0][i])
    if desired[i] == 0 and saida[0][i] > 0.5:
        print ' +'
        erro+=1.0
    elif desired[i] == 1 and saida[0][i] < 0.5:
        print ' +'
        erro+=1.0

print '\n\nEpocas: '+str(epocas)
print 'Erro da rede: '+str(output[4])
print 'Acc:'+str(1.0-(erro/len(input)))